package dao.impl;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import dao.LowAuditDao;
import po.LowAudit;

@Repository
public class LowAuditDaoImpl implements LowAuditDao {
	
	@PersistenceContext(name="un")
	private EntityManager entityManager;

	@Override
	public List<LowAudit> listAllLowAudit() {
		// TODO Auto-generated method stub
		String jpql = "from LowAudit la where la.status = 0 order by la.createDate";
		return entityManager.createQuery(jpql).getResultList();
	}

	@Override
	@Transactional
	public String insertlowAudit(LowAudit lowAudit) {
		// TODO Auto-generated method stub
		entityManager.persist(lowAudit);
		return lowAudit.getmId();
	}

	@Override
	@Transactional
	public String updateLowAuditStatus(LowAudit lowAudit) {
		// TODO Auto-generated method stub
		entityManager.merge(lowAudit);
		return lowAudit.getmId();
	}

	@Override
	public LowAudit findLowAuditById(String id) {
		// TODO Auto-generated method stub
		LowAudit lowAudit = entityManager.find(LowAudit.class, id);
		return lowAudit;
	}
	
	

}
